HEART DISEASE DIAGNOSTIC ANALYSIS¶

Importing all necessary Libraries:

In [1]:
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
import pandas as pd
import ydata_profiling
import warnings
warnings.filterwarnings("ignore")

Loading dataset by using pandas:

In [2]:
df=pd.read_csv("heart.csv")
print(df.to_string())
      age  sex  cp  trtbps  chol  fbs  restecg  thalachh  exng  oldpeak  slp  caa  thall  output
0    63.0  1.0   3   145.0   233  1.0      0.0       150     0      2.3  0.0  0.0    1.0     1.0
1    37.0  1.0   2   130.0   250  0.0      1.0       187     0      3.5  0.0  0.0    2.0     1.0
2    41.0  0.0   1   130.0   204  0.0      0.0       172     0      1.4  2.0  0.0    2.0     1.0
3     NaN  1.0   1   120.0   236  0.0      1.0       178     0      0.8  2.0  0.0    2.0     1.0
4    57.0  0.0   0   120.0   354  0.0      1.0       163     1      0.6  2.0  0.0    2.0     1.0
5    57.0  1.0   0   140.0   192  0.0      1.0       148     0      0.4  1.0  0.0    1.0     1.0
6    56.0  0.0   1     NaN   294  0.0      0.0       153     0      1.3  1.0  0.0    2.0     1.0
7    44.0  1.0   1   120.0   263  0.0      1.0       173     0      0.0  2.0  0.0    3.0     1.0
8    52.0  1.0   2   172.0   199  1.0      1.0       162     0      0.5  2.0  0.0    3.0     1.0
9    57.0  1.0   2   150.0   168  0.0      1.0       174     0      1.6  2.0  0.0    2.0     1.0
10   54.0  1.0   0   140.0   239  0.0      1.0       160     0      1.2  2.0  0.0    2.0     1.0
11   48.0  0.0   2   130.0   275  0.0      1.0       139     0      0.2  2.0  0.0    2.0     1.0
12   49.0  1.0   1     NaN   266  0.0      1.0       171     0      0.6  2.0  0.0    2.0     1.0
13    NaN  1.0   3   110.0   211  0.0      0.0       144     1      1.8  1.0  0.0    2.0     1.0
14   58.0  0.0   3   150.0   283  1.0      0.0       162     0      1.0  2.0  0.0    2.0     1.0
15   50.0  0.0   2   120.0   219  0.0      1.0       158     0      1.6  1.0  0.0    2.0     1.0
16   58.0  0.0   2   120.0   340  0.0      1.0       172     0      0.0  2.0  0.0    2.0     1.0
17   66.0  0.0   3   150.0   226  0.0      1.0       114     0      2.6  0.0  0.0    2.0     1.0
18   43.0  1.0   0   150.0   247  0.0      1.0       171     0      1.5  2.0  0.0    2.0     1.0
19   69.0  0.0   3   140.0   239  0.0      1.0       151     0      1.8  2.0  2.0    2.0     1.0
20   59.0  1.0   0     NaN   234  0.0      1.0       161     0      0.5  1.0  0.0    3.0     1.0
21   44.0  1.0   2   130.0   233  0.0      1.0       179     1      0.4  2.0  0.0    2.0     1.0
22   42.0  1.0   0   140.0   226  0.0      1.0       178     0      0.0  2.0  0.0    2.0     1.0
23   61.0  1.0   2   150.0   243  1.0      1.0       137     1      1.0  1.0  0.0    2.0     1.0
24   40.0  1.0   3   140.0   199  0.0      1.0       178     1      1.4  2.0  0.0    3.0     1.0
25   71.0  0.0   1   160.0   302  0.0      1.0       162     0      0.4  2.0  2.0    2.0     1.0
26   59.0  1.0   2   150.0   212  1.0      1.0       157     0      1.6  2.0  0.0    2.0     1.0
27   51.0  1.0   2   110.0   175  0.0      1.0       123     0      0.6  2.0  0.0    2.0     1.0
28   65.0  0.0   2   140.0   417  1.0      0.0       157     0      0.8  2.0  1.0    2.0     1.0
29   53.0  1.0   2   130.0   197  1.0      0.0       152     0      1.2  0.0  0.0    2.0     1.0
30   41.0  0.0   1   105.0   198  0.0      1.0       168     0      0.0  2.0  1.0    2.0     1.0
31   65.0  1.0   0   120.0   177  0.0      1.0       140     0      0.4  2.0  0.0    3.0     1.0
32   44.0  1.0   1   130.0   219  0.0      0.0       188     0      0.0  2.0  0.0    2.0     1.0
33   54.0  1.0   2   125.0   273  0.0      0.0       152     0      0.5  0.0  1.0    2.0     1.0
34   51.0  1.0   3     NaN   213  0.0      0.0       125     1      1.4  2.0  1.0    2.0     1.0
35   46.0  0.0   2   142.0   177  0.0      0.0       160     1      1.4  0.0  0.0    2.0     1.0
36   54.0  0.0   2   135.0   304  1.0      1.0       170     0      0.0  2.0  0.0    2.0     1.0
37   54.0  1.0   2   150.0   232  0.0      0.0       165     0      1.6  2.0  0.0    3.0     1.0
38   65.0  0.0   2   155.0   269  0.0      1.0       148     0      0.8  2.0  0.0    2.0     1.0
39   65.0  0.0   2   160.0   360  0.0      0.0       151     0      0.8  2.0  0.0    2.0     1.0
40   51.0  0.0   2   140.0   308  0.0      0.0       142     0      1.5  2.0  1.0    2.0     1.0
41   48.0  1.0   1   130.0   245  0.0      0.0       180     0      0.2  1.0  0.0    2.0     1.0
42   45.0  1.0   0   104.0   208  0.0      0.0       148     1      3.0  1.0  0.0    2.0     1.0
43   53.0  0.0   0   130.0   264  0.0      0.0       143     0      0.4  1.0  0.0    2.0     1.0
44   39.0  1.0   2   140.0   321  0.0      0.0       182     0      0.0  2.0  0.0    2.0     1.0
45   52.0  1.0   1     NaN   325  0.0      1.0       172     0      0.2  2.0  0.0    2.0     1.0
46   44.0  1.0   2   140.0   235  0.0      NaN       180     0      0.0  2.0  0.0    2.0     1.0
47   47.0  1.0   2   138.0   257  0.0      0.0       156     0      0.0  2.0  0.0    2.0     1.0
48   53.0  0.0   2   128.0   216  0.0      0.0       115     0      0.0  2.0  0.0    0.0     1.0
49   53.0  0.0   0   138.0   234  0.0      0.0       160     0      0.0  2.0  0.0    2.0     1.0
50   51.0  0.0   2   130.0   256  0.0      0.0       149     0      0.5  2.0  0.0    2.0     1.0
51   66.0  1.0   0   120.0   302  0.0      NaN       151     0      0.4  1.0  0.0    2.0     1.0
52   62.0  1.0   2   130.0   231  0.0      NaN       146     0      1.8  1.0  3.0    3.0     1.0
53   44.0  0.0   2   108.0   141  0.0      1.0       175     0      0.6  1.0  0.0    2.0     1.0
54   63.0  0.0   2   135.0   252  0.0      0.0       172     0      0.0  2.0  0.0    2.0     1.0
55   52.0  1.0   1   134.0   201  0.0      1.0       158     0      0.8  2.0  1.0    2.0     1.0
56   48.0  1.0   0   122.0   222  0.0      0.0       186     0      0.0  2.0  0.0    2.0     1.0
57   45.0  1.0   0     NaN   260  0.0      NaN       185     0      0.0  2.0  0.0    2.0     1.0
58   34.0  1.0   3   118.0   182  0.0      0.0       174     0      0.0  2.0  0.0    2.0     1.0
59   57.0  0.0   0   128.0   303  0.0      0.0       159     0      0.0  2.0  1.0    2.0     1.0
60   71.0  0.0   2   110.0   265  1.0      0.0       130     0      0.0  2.0  1.0    2.0     1.0
61   54.0  1.0   1   108.0   309  0.0      1.0       156     0      0.0  2.0  0.0    3.0     1.0
62   52.0  1.0   3   118.0   186  0.0      NaN       190     0      0.0  1.0  0.0    1.0     1.0
63   41.0  1.0   1   135.0   203  0.0      1.0       132     0      0.0  1.0  0.0    1.0     1.0
64   58.0  1.0   2   140.0   211  1.0      0.0       165     0      0.0  2.0  0.0    2.0     1.0
65   35.0  0.0   0     NaN   183  0.0      1.0       182     0      1.4  2.0  0.0    2.0     1.0
66   51.0  1.0   2     NaN   222  0.0      1.0       143     1      1.2  1.0  0.0    2.0     1.0
67   45.0  0.0   1   130.0   234  0.0      0.0       175     0      0.6  1.0  0.0    2.0     1.0
68   44.0  1.0   1   120.0   220  0.0      1.0       170     0      0.0  2.0  0.0    2.0     1.0
69   62.0  0.0   0   124.0   209  0.0      1.0       163     0      0.0  2.0  0.0    2.0     1.0
70   54.0  1.0   2   120.0   258  0.0      0.0       147     0      0.4  1.0  0.0    3.0     1.0
71   51.0  1.0   2    94.0   227  0.0      1.0       154     1      0.0  2.0  1.0    3.0     1.0
72   29.0  1.0   1   130.0   204  0.0      0.0       202     0      0.0  2.0  0.0    2.0     1.0
73   51.0  1.0   0   140.0   261  0.0      0.0       186     1      0.0  2.0  0.0    2.0     1.0
74   43.0  0.0   2   122.0   213  0.0      1.0       165     0      0.2  1.0  0.0    2.0     1.0
75   55.0  0.0   1   135.0   250  0.0      0.0       161     0      1.4  1.0  0.0    2.0     1.0
76   51.0  1.0   2   125.0   245  1.0      0.0       166     0      2.4  1.0  0.0    2.0     1.0
77   59.0  1.0   1   140.0   221  0.0      1.0       164     1      0.0  2.0  0.0    2.0     1.0
78   52.0  1.0   1   128.0   205  1.0      1.0       184     0      0.0  2.0  0.0    2.0     1.0
79   58.0  1.0   2   105.0   240  0.0      0.0       154     1      0.6  1.0  0.0    3.0     1.0
80   41.0  1.0   2   112.0   250  0.0      1.0       179     0      0.0  2.0  0.0    2.0     1.0
81   45.0  1.0   1   128.0   308  0.0      0.0       170     0      0.0  2.0  0.0    2.0     1.0
82   60.0  0.0   2   102.0   318  0.0      1.0       160     0      0.0  2.0  1.0    2.0     1.0
83   52.0  1.0   3   152.0   298  1.0      1.0       178     0      1.2  1.0  0.0    3.0     1.0
84   42.0  0.0   0   102.0   265  0.0      0.0       122     0      0.6  1.0  0.0    2.0     1.0
85   67.0  0.0   2   115.0   564  0.0      0.0       160     0      1.6  1.0  0.0    3.0     1.0
86   68.0  1.0   2   118.0   277  0.0      1.0       151     0      1.0  2.0  1.0    3.0     1.0
87   46.0  1.0   1   101.0   197  1.0      1.0       156     0      0.0  2.0  0.0    3.0     1.0
88   54.0  0.0   2   110.0   214  0.0      1.0       158     0      1.6  1.0  0.0    2.0     1.0
89   58.0  0.0   0   100.0   248  0.0      0.0       122     0      1.0  1.0  0.0    2.0     1.0
90   48.0  1.0   2   124.0   255  1.0      1.0       175     0      0.0  2.0  2.0    2.0     1.0
91   57.0  1.0   0   132.0   207  NaN      1.0       168     1      0.0  2.0  0.0    3.0     1.0
92   52.0  1.0   2   138.0   223  0.0      1.0       169     0      0.0  2.0  4.0    2.0     1.0
93   54.0  0.0   1   132.0   288  1.0      0.0       159     1      0.0  2.0  1.0    2.0     1.0
94   45.0  0.0   1   112.0   160  0.0      1.0       138     0      NaN  1.0  NaN    2.0     1.0
95   53.0  1.0   0   142.0   226  NaN      0.0       111     1      0.0  NaN  0.0    3.0     1.0
96   62.0  NaN   0   140.0   394  0.0      0.0       157     0      1.2  1.0  0.0    2.0     1.0
97   52.0  1.0   0   108.0   233  1.0      1.0       147     0      0.1  2.0  3.0    3.0     1.0
98   43.0  1.0   2   130.0   315  0.0      1.0       162     0      1.9  2.0  1.0    2.0     1.0
99   53.0  1.0   2   130.0   246  1.0      0.0       173     0      0.0  2.0  3.0    2.0     1.0
100  42.0  1.0   3   148.0   244  NaN      0.0       178     0      NaN  2.0  2.0    2.0     1.0
101  59.0  1.0   3   178.0   270  0.0      0.0       145     0      4.2  0.0  0.0    NaN     1.0
102   NaN  0.0   1   140.0   195  0.0      1.0       179     0      0.0  2.0  2.0    2.0     1.0
103  42.0  1.0   2   120.0   240  1.0      1.0       194     0      0.8  0.0  NaN    3.0     1.0
104  50.0  1.0   2   129.0   196  0.0      1.0       163     0      0.0  2.0  0.0    2.0     1.0
105  68.0  0.0   2   120.0   211  0.0      0.0       115     0      1.5  1.0  0.0    2.0     1.0
106  69.0  1.0   3   160.0   234  NaN      0.0       131     0      0.1  1.0  1.0    2.0     1.0
107  45.0  0.0   0   138.0   236  0.0      0.0       152     1      NaN  1.0  0.0    2.0     NaN
108  50.0  0.0   1   120.0   244  0.0      NaN       162     0      1.1  2.0  0.0    NaN     1.0
109  50.0  0.0   0   110.0   254  0.0      0.0       159     0      0.0  2.0  0.0    2.0     1.0
110  64.0  0.0   0   180.0   325  0.0      1.0       154     1      0.0  2.0  0.0    2.0     1.0
111  57.0  1.0   2   150.0   126  1.0      1.0       173     0      0.2  2.0  1.0    3.0     1.0
112  64.0  0.0   2   140.0   313  0.0      1.0       133     0      0.2  2.0  0.0    3.0     1.0
113  43.0  1.0   0   110.0   211  0.0      1.0       161     0      0.0  2.0  0.0    3.0     1.0
114  55.0  1.0   1   130.0   262  0.0      1.0       155     0      0.0  2.0  0.0    2.0     1.0
115  37.0  0.0   2   120.0   215  0.0      1.0       170     0      0.0  2.0  0.0    2.0     1.0
116  41.0  1.0   2   130.0   214  0.0      0.0       168     0      2.0  1.0  0.0    2.0     1.0
117  56.0  1.0   3   120.0   193  0.0      0.0       162     0      1.9  1.0  0.0    3.0     1.0
118  46.0  0.0   1   105.0   204  0.0      1.0       172     0      0.0  2.0  0.0    2.0     1.0
119  46.0  0.0   0   138.0   243  0.0      0.0       152     1      0.0  1.0  0.0    2.0     1.0
120  64.0  0.0   0   130.0   303  0.0      1.0       122     0      2.0  1.0  2.0    2.0     1.0
121  59.0  1.0   0   138.0   271  0.0      0.0       182     0      0.0  2.0  0.0    2.0     1.0
122  41.0  0.0   2   112.0   268  0.0      0.0       172     1      0.0  2.0  0.0    2.0     1.0
123  54.0  0.0   2   108.0   267  0.0      0.0       167     0      0.0  2.0  0.0    2.0     1.0
124  39.0  0.0   2    94.0   199  0.0      1.0       179     0      0.0  2.0  0.0    2.0     1.0
125  34.0  0.0   1   118.0   210  0.0      1.0       192     0      0.7  2.0  0.0    2.0     1.0
126  47.0  1.0   0   112.0   204  0.0      1.0       143     0      0.1  2.0  0.0    2.0     1.0
127  67.0  0.0   2   152.0   277  0.0      1.0       172     0      0.0  2.0  1.0    2.0     1.0
128  52.0  0.0   2   136.0   196  0.0      0.0       169     0      0.1  1.0  0.0    2.0     1.0
129  74.0  0.0   1   120.0   269  0.0      0.0       121     1      0.2  2.0  1.0    2.0     1.0
130  54.0  0.0   2   160.0   201  0.0      1.0       163     0      0.0  2.0  1.0    2.0     1.0
131  49.0  0.0   1   134.0   271  0.0      1.0       162     0      0.0  1.0  0.0    2.0     1.0
132  42.0  1.0   1   120.0   295  0.0      1.0       162     0      0.0  2.0  0.0    2.0     1.0
133  41.0  1.0   1   110.0   235  0.0      1.0       153     0      0.0  2.0  0.0    2.0     1.0
134  41.0  0.0   1   126.0   306  0.0      1.0       163     0      0.0  2.0  0.0    2.0     1.0
135  49.0  0.0   0   130.0   269  0.0      1.0       163     0      0.0  2.0  0.0    2.0     1.0
136  60.0  0.0   2   120.0   178  1.0      1.0        96     0      0.0  2.0  0.0    2.0     1.0
137  62.0  1.0   1   128.0   208  1.0      0.0       140     0      0.0  2.0  0.0    2.0     1.0
138  57.0  1.0   0   110.0   201  0.0      1.0       126     1      1.5  1.0  0.0    1.0     1.0
139  64.0  1.0   0   128.0   263  0.0      1.0       105     1      0.2  1.0  1.0    3.0     1.0
140  51.0  0.0   2   120.0   295  0.0      0.0       157     0      0.6  2.0  0.0    2.0     1.0
141  43.0  1.0   0   115.0   303  0.0      1.0       181     0      1.2  1.0  0.0    2.0     1.0
142  42.0  0.0   2   120.0   209  0.0      1.0       173     0      0.0  1.0  0.0    2.0     1.0
143  67.0  0.0   0   106.0   223  0.0      1.0       142     0      0.3  2.0  2.0    2.0     1.0
144  76.0  0.0   2   140.0   197  0.0      2.0       116     0      1.1  1.0  0.0    2.0     1.0
145  70.0  1.0   1   156.0   245  0.0      0.0       143     0      0.0  2.0  0.0    2.0     1.0
146  44.0  0.0   2   118.0   242  0.0      1.0       149     0      0.3  1.0  1.0    2.0     1.0
147  60.0  0.0   3   150.0   240  0.0      1.0       171     0      0.9  2.0  0.0    2.0     1.0
148  44.0  1.0   2   120.0   226  0.0      1.0       169     0      0.0  2.0  0.0    2.0     1.0
149  42.0  1.0   2   130.0   180  0.0      1.0       150     0      0.0  2.0  0.0    2.0     1.0
150  66.0  1.0   0   160.0   228  0.0      0.0       138     0      2.3  2.0  0.0    1.0     1.0
151  71.0  0.0   0   112.0   149  0.0      1.0       125     0      1.6  1.0  0.0    2.0     1.0
152  64.0  1.0   3   170.0   227  0.0      0.0       155     0      0.6  1.0  0.0    3.0     1.0
153  66.0  0.0   2   146.0   278  0.0      0.0       152     0      0.0  1.0  1.0    2.0     1.0
154  39.0  0.0   2   138.0   220  0.0      1.0       152     0      0.0  1.0  0.0    2.0     1.0
155  58.0  0.0   0   130.0   197  0.0      1.0       131     0      0.6  1.0  0.0    2.0     1.0
156  47.0  1.0   2   130.0   253  0.0      1.0       179     0      0.0  2.0  0.0    2.0     1.0
157  35.0  1.0   1   122.0   192  0.0      1.0       174     0      0.0  2.0  0.0    2.0     1.0
158  58.0  1.0   1   125.0   220  0.0      1.0       144     0      0.4  1.0  4.0    3.0     1.0
159  56.0  1.0   1   130.0   221  0.0      0.0       163     0      0.0  2.0  0.0    3.0     1.0
160  56.0  1.0   1   120.0   240  0.0      1.0       169     0      0.0  0.0  0.0    2.0     1.0
161  55.0  0.0   1   132.0   342  0.0      1.0       166     0      1.2  2.0  0.0    2.0     1.0
162  41.0  1.0   1   120.0   157  0.0      1.0       182     0      0.0  2.0  0.0    2.0     1.0
163  38.0  1.0   2   138.0   175  0.0      1.0       173     0      0.0  2.0  4.0    2.0     1.0
164  38.0  1.0   2   138.0   175  0.0      1.0       173     0      0.0  2.0  4.0    2.0     1.0
165  67.0  1.0   0   160.0   286  0.0      0.0       108     1      1.5  1.0  3.0    2.0     0.0
166  67.0  1.0   0   120.0   229  0.0      0.0       129     1      2.6  1.0  2.0    3.0     0.0
167  62.0  0.0   0   140.0   268  0.0      0.0       160     0      3.6  0.0  2.0    2.0     0.0
168  63.0  1.0   0   130.0   254  0.0      0.0       147     0      1.4  1.0  1.0    3.0     0.0
169  53.0  1.0   0   140.0   203  1.0      0.0       155     1      3.1  0.0  0.0    3.0     0.0
170  56.0  1.0   2   130.0   256  1.0      0.0       142     1      0.6  1.0  1.0    1.0     0.0
171  48.0  1.0   1   110.0   229  0.0      1.0       168     0      1.0  0.0  0.0    3.0     0.0
172  58.0  1.0   1   120.0   284  0.0      0.0       160     0      1.8  1.0  0.0    2.0     0.0
173  58.0  1.0   2   132.0   224  0.0      0.0       173     0      3.2  2.0  2.0    3.0     0.0
174  60.0  1.0   0   130.0   206  0.0      0.0       132     1      2.4  1.0  2.0    3.0     0.0
175  40.0  1.0   0   110.0   167  0.0      0.0       114     1      2.0  1.0  0.0    3.0     0.0
176  60.0  1.0   0   117.0   230  1.0      1.0       160     1      1.4  2.0  2.0    3.0     0.0
177  64.0  1.0   2   140.0   335  0.0      1.0       158     0      0.0  2.0  0.0    2.0     0.0
178  43.0  1.0   0   120.0   177  0.0      0.0       120     1      2.5  1.0  0.0    3.0     0.0
179  57.0  1.0   0   150.0   276  0.0      0.0       112     1      0.6  1.0  1.0    1.0     0.0
180  55.0  1.0   0   132.0   353  0.0      1.0       132     1      1.2  1.0  1.0    3.0     0.0
181  65.0  0.0   0   150.0   225  0.0      0.0       114     0      1.0  1.0  3.0    3.0     0.0
182  61.0  0.0   0   130.0   330  0.0      0.0       169     0      0.0  2.0  0.0    2.0     0.0
183  58.0  1.0   2   112.0   230  0.0      0.0       165     0      2.5  1.0  1.0    3.0     0.0
184  50.0  1.0   0   150.0   243  0.0      0.0       128     0      2.6  1.0  0.0    3.0     0.0
185  44.0  1.0   0   112.0   290  0.0      0.0       153     0      0.0  2.0  1.0    2.0     0.0
186  60.0  1.0   0   130.0   253  0.0      1.0       144     1      1.4  2.0  1.0    3.0     0.0
187  54.0  1.0   0   124.0   266  0.0      0.0       109     1      2.2  1.0  1.0    3.0     0.0
188  50.0  1.0   2   140.0   233  0.0      1.0       163     0      0.6  1.0  1.0    3.0     0.0
189  41.0  1.0   0   110.0   172  0.0      0.0       158     0      0.0  2.0  0.0    3.0     0.0
190  51.0  0.0   0   130.0   305  0.0      1.0       142     1      1.2  1.0  0.0    3.0     0.0
191  58.0  1.0   0   128.0   216  0.0      0.0       131     1      2.2  1.0  3.0    3.0     0.0
192  54.0  1.0   0   120.0   188  0.0      1.0       113     0      1.4  1.0  1.0    3.0     0.0
193  60.0  1.0   0   145.0   282  0.0      0.0       142     1      2.8  1.0  2.0    3.0     0.0
194  60.0  1.0   2   140.0   185  0.0      0.0       155     0      3.0  1.0  0.0    2.0     0.0
195  59.0  1.0   0   170.0   326  0.0      0.0       140     1      3.4  0.0  0.0    3.0     0.0
196  46.0  1.0   2   150.0   231  0.0      1.0       147     0      3.6  1.0  0.0    2.0     0.0
197  67.0  1.0   0   125.0   254  1.0      1.0       163     0      0.2  1.0  2.0    3.0     0.0
198  62.0  1.0   0   120.0   267  0.0      1.0        99     1      1.8  1.0  2.0    3.0     0.0
199  65.0  1.0   0   110.0   248  0.0      0.0       158     0      0.6  2.0  2.0    1.0     0.0
200  44.0  1.0   0   110.0   197  0.0      0.0       177     0      0.0  2.0  1.0    2.0     0.0
201  60.0  1.0   0   125.0   258  0.0      0.0       141     1      2.8  1.0  1.0    3.0     0.0
202  58.0  1.0   0   150.0   270  0.0      0.0       111     1      0.8  2.0  0.0    3.0     0.0
203  68.0  1.0   2   180.0   274  1.0      0.0       150     1      1.6  1.0  0.0    3.0     0.0
204  62.0  0.0   0   160.0   164  0.0      0.0       145     0      6.2  0.0  3.0    3.0     0.0
205  52.0  1.0   0   128.0   255  0.0      1.0       161     1      0.0  2.0  1.0    3.0     0.0
206  59.0  1.0   0   110.0   239  0.0      0.0       142     1      1.2  1.0  1.0    3.0     0.0
207  60.0  0.0   0   150.0   258  0.0      0.0       157     0      2.6  1.0  2.0    3.0     0.0
208  49.0  1.0   2   120.0   188  0.0      1.0       139     0      2.0  1.0  3.0    3.0     0.0
209  59.0  1.0   0   140.0   177  0.0      1.0       162     1      0.0  2.0  1.0    3.0     0.0
210  57.0  1.0   2   128.0   229  0.0      0.0       150     0      0.4  1.0  1.0    3.0     0.0
211  61.0  1.0   0   120.0   260  0.0      1.0       140     1      3.6  1.0  1.0    3.0     0.0
212  39.0  1.0   0   118.0   219  0.0      1.0       140     0      1.2  1.0  0.0    3.0     0.0
213  61.0  0.0   0   145.0   307  0.0      0.0       146     1      1.0  1.0  0.0    3.0     0.0
214  56.0  1.0   0   125.0   249  1.0      0.0       144     1      1.2  1.0  1.0    2.0     0.0
215  43.0  0.0   0   132.0   341  1.0      0.0       136     1      3.0  1.0  0.0    3.0     0.0
216  62.0  0.0   2   130.0   263  0.0      1.0        97     0      1.2  1.0  1.0    3.0     0.0
217  63.0  1.0   0   130.0   330  1.0      0.0       132     1      1.8  2.0  3.0    3.0     0.0
218  65.0  1.0   0   135.0   254  0.0      0.0       127     0      2.8  1.0  1.0    3.0     0.0
219  48.0  1.0   0   130.0   256  1.0      0.0       150     1      0.0  2.0  2.0    3.0     0.0
220  63.0  0.0   0   150.0   407  0.0      0.0       154     0      4.0  1.0  3.0    3.0     0.0
221  55.0  1.0   0   140.0   217  0.0      1.0       111     1      5.6  0.0  0.0    3.0     0.0
222  65.0  1.0   3   138.0   282  1.0      0.0       174     0      1.4  1.0  1.0    2.0     0.0
223  56.0  0.0   0   200.0   288  1.0      0.0       133     1      4.0  0.0  2.0    3.0     0.0
224  54.0  1.0   0   110.0   239  0.0      1.0       126     1      2.8  1.0  1.0    3.0     0.0
225  70.0  1.0   0   145.0   174  0.0      1.0       125     1      2.6  0.0  0.0    3.0     0.0
226  62.0  1.0   1   120.0   281  0.0      0.0       103     0      1.4  1.0  1.0    3.0     0.0
227  35.0  1.0   0   120.0   198  0.0      1.0       130     1      1.6  1.0  0.0    3.0     0.0
228  59.0  1.0   3   170.0   288  0.0      0.0       159     0      0.2  1.0  0.0    3.0     0.0
229  64.0  1.0   2   125.0   309  0.0      1.0       131     1      1.8  1.0  0.0    3.0     0.0
230  47.0  1.0   2   108.0   243  0.0      1.0       152     0      0.0  2.0  0.0    2.0     0.0
231  57.0  1.0   0   165.0   289  1.0      0.0       124     0      1.0  1.0  3.0    3.0     0.0
232  55.0  1.0   0   160.0   289  0.0      0.0       145     1      0.8  1.0  1.0    3.0     0.0
233  64.0  1.0   0   120.0   246  0.0      0.0        96     1      2.2  0.0  1.0    2.0     0.0
234  70.0  1.0   0   130.0   322  0.0      0.0       109     0      2.4  1.0  3.0    2.0     0.0
235  51.0  1.0   0   140.0   299  0.0      1.0       173     1      1.6  2.0  0.0    3.0     0.0
236  58.0  1.0   0   125.0   300  0.0      0.0       171     0      0.0  2.0  2.0    3.0     0.0
237  60.0  1.0   0   140.0   293  0.0      0.0       170     0      1.2  1.0  2.0    3.0     0.0
238  77.0  1.0   0   125.0   304  0.0      0.0       162     1      0.0  2.0  3.0    2.0     0.0
239  35.0  1.0   0   126.0   282  0.0      0.0       156     1      0.0  2.0  0.0    3.0     0.0
240  70.0  1.0   2   160.0   269  0.0      1.0       112     1      2.9  1.0  1.0    3.0     0.0
241  59.0  0.0   0   174.0   249  0.0      1.0       143     1      0.0  1.0  0.0    2.0     0.0
242  64.0  1.0   0   145.0   212  0.0      0.0       132     0      2.0  1.0  2.0    1.0     0.0
243  57.0  1.0   0   152.0   274  0.0      1.0        88     1      1.2  1.0  1.0    3.0     0.0
244  56.0  1.0   0   132.0   184  0.0      0.0       105     1      2.1  1.0  1.0    1.0     0.0
245  48.0  1.0   0   124.0   274  0.0      0.0       166     0      0.5  1.0  0.0    3.0     0.0
246  56.0  0.0   0   134.0   409  0.0      0.0       150     1      1.9  1.0  2.0    3.0     0.0
247  66.0  1.0   1   160.0   246  0.0      1.0       120     1      0.0  1.0  3.0    1.0     0.0
248  54.0  1.0   1   192.0   283  0.0      0.0       195     0      0.0  2.0  1.0    3.0     0.0
249  69.0  1.0   2   140.0   254  0.0      0.0       146     0      2.0  1.0  3.0    3.0     0.0
250  51.0  1.0   0   140.0   298  0.0      1.0       122     1      4.2  1.0  3.0    3.0     0.0
251  43.0  1.0   0   132.0   247  1.0      0.0       143     1      0.1  1.0  4.0    3.0     0.0
252  62.0  0.0   0   138.0   294  1.0      1.0       106     0      1.9  1.0  3.0    2.0     0.0
253  67.0  1.0   0   100.0   299  0.0      0.0       125     1      0.9  1.0  2.0    2.0     0.0
254  59.0  1.0   3   160.0   273  0.0      0.0       125     0      0.0  2.0  0.0    2.0     0.0
255  45.0  1.0   0   142.0   309  0.0      0.0       147     1      0.0  1.0  3.0    3.0     0.0
256  58.0  1.0   0   128.0   259  0.0      0.0       130     1      3.0  1.0  2.0    3.0     0.0
257  50.0  1.0   0   144.0   200  0.0      0.0       126     1      0.9  1.0  0.0    3.0     0.0
258  62.0  0.0   0   150.0   244  0.0      1.0       154     1      1.4  1.0  0.0    2.0     0.0
259  38.0  1.0   3   120.0   231  0.0      1.0       182     1      3.8  1.0  0.0    3.0     0.0
260  66.0  0.0   0   178.0   228  1.0      1.0       165     1      1.0  1.0  2.0    3.0     0.0
261  52.0  1.0   0   112.0   230  0.0      1.0       160     0      0.0  2.0  1.0    2.0     0.0
262  53.0  1.0   0   123.0   282  0.0      1.0        95     1      2.0  1.0  2.0    3.0     0.0
263  63.0  0.0   0   108.0   269  0.0      1.0       169     1      1.8  1.0  2.0    2.0     0.0
264  54.0  1.0   0   110.0   206  0.0      0.0       108     1      0.0  1.0  1.0    2.0     0.0
265  66.0  1.0   0   112.0   212  0.0      0.0       132     1      0.1  2.0  1.0    2.0     0.0
266  55.0  0.0   0   180.0   327  0.0      2.0       117     1      3.4  1.0  0.0    2.0     0.0
267  49.0  1.0   2   118.0   149  0.0      0.0       126     0      0.8  2.0  3.0    2.0     0.0
268  54.0  1.0   0   122.0   286  0.0      0.0       116     1      3.2  1.0  2.0    2.0     0.0
269  56.0  1.0   0   130.0   283  1.0      0.0       103     1      1.6  0.0  0.0    3.0     0.0
270  46.0  1.0   0   120.0   249  0.0      0.0       144     0      0.8  2.0  0.0    3.0     0.0
271  61.0  1.0   3   134.0   234  0.0      1.0       145     0      2.6  1.0  2.0    2.0     0.0
272  67.0  1.0   0   120.0   237  0.0      1.0        71     0      1.0  1.0  0.0    2.0     0.0
273  58.0  1.0   0   100.0   234  0.0      1.0       156     0      0.1  2.0  1.0    3.0     0.0
274  47.0  1.0   0   110.0   275  0.0      0.0       118     1      1.0  1.0  1.0    2.0     0.0
275  52.0  1.0   0   125.0   212  0.0      1.0       168     0      1.0  2.0  2.0    3.0     0.0
276  58.0  1.0   0   146.0   218  0.0      1.0       105     0      2.0  1.0  1.0    3.0     0.0
277  57.0  1.0   1   124.0   261  0.0      1.0       141     0      0.3  2.0  0.0    3.0     0.0
278  58.0  0.0   1   136.0   319  1.0      0.0       152     0      0.0  2.0  2.0    2.0     0.0
279  61.0  1.0   0   138.0   166  0.0      0.0       125     1      3.6  1.0  1.0    2.0     0.0
280  42.0  1.0   0   136.0   315  0.0      1.0       125     1      1.8  1.0  0.0    1.0     0.0
281  52.0  1.0   0   128.0   204  1.0      1.0       156     1      1.0  1.0  0.0    0.0     0.0
282  59.0  1.0   2   126.0   218  1.0      1.0       134     0      2.2  1.0  1.0    1.0     0.0
283  40.0  1.0   0   152.0   223  0.0      1.0       181     0      0.0  2.0  0.0    3.0     0.0
284  61.0  1.0   0   140.0   207  0.0      0.0       138     1      1.9  2.0  1.0    3.0     0.0
285  46.0  1.0   0   140.0   311  0.0      1.0       120     1      1.8  1.0  2.0    3.0     0.0
286  59.0  1.0   3   134.0   204  0.0      1.0       162     0      0.8  2.0  2.0    2.0     0.0
287  57.0  1.0   1   154.0   232  0.0      0.0       164     0      0.0  2.0  1.0    2.0     0.0
288  57.0  1.0   0   110.0   335  0.0      1.0       143     1      3.0  1.0  1.0    3.0     0.0
289  55.0  0.0   0   128.0   205  0.0      2.0       130     1      2.0  1.0  1.0    3.0     0.0
290  61.0  1.0   0   148.0   203  0.0      1.0       161     0      0.0  2.0  1.0    3.0     0.0
291  58.0  1.0   0   114.0   318  0.0      2.0       140     0      4.4  0.0  3.0    1.0     0.0
292  58.0  0.0   0   170.0   225  1.0      0.0       146     1      2.8  1.0  2.0    1.0     0.0
293  67.0  1.0   2   152.0   212  0.0      0.0       150     0      0.8  1.0  0.0    3.0     0.0
294  44.0  1.0   0   120.0   169  0.0      1.0       144     1      2.8  0.0  0.0    1.0     0.0
295  63.0  1.0   0   140.0   187  0.0      0.0       144     1      4.0  2.0  2.0    3.0     0.0
296  63.0  0.0   0   124.0   197  0.0      1.0       136     1      0.0  1.0  0.0    2.0     0.0
297  59.0  1.0   0   164.0   176  1.0      0.0        90     0      1.0  1.0  2.0    1.0     0.0
298  57.0  0.0   0   140.0   241  0.0      1.0       123     1      0.2  1.0  0.0    3.0     0.0
299  45.0  1.0   3   110.0   264  0.0      1.0       132     0      1.2  1.0  0.0    3.0     0.0
300  68.0  1.0   0   144.0   193  1.0      1.0       141     0      3.4  1.0  2.0    3.0     0.0
301  57.0  1.0   0   130.0   131  0.0      1.0       115     1      1.2  1.0  1.0    3.0     0.0
302  57.0  0.0   1   130.0   236  0.0      0.0       174     0      0.0  1.0  1.0    2.0     0.0
In [3]:
df.head()
Out[3]:
age sex cp trtbps chol fbs restecg thalachh exng oldpeak slp caa thall output
0 63.0 1.0 3 145.0 233 1.0 0.0 150 0 2.3 0.0 0.0 1.0 1.0
1 37.0 1.0 2 130.0 250 0.0 1.0 187 0 3.5 0.0 0.0 2.0 1.0
2 41.0 0.0 1 130.0 204 0.0 0.0 172 0 1.4 2.0 0.0 2.0 1.0
3 NaN 1.0 1 120.0 236 0.0 1.0 178 0 0.8 2.0 0.0 2.0 1.0
4 57.0 0.0 0 120.0 354 0.0 1.0 163 1 0.6 2.0 0.0 2.0 1.0
In [4]:
df.shape
Out[4]:
(303, 14)
In [5]:
df.info()
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 303 entries, 0 to 302
Data columns (total 14 columns):
 #   Column    Non-Null Count  Dtype  
---  ------    --------------  -----  
 0   age       300 non-null    float64
 1   sex       302 non-null    float64
 2   cp        303 non-null    int64  
 3   trtbps    295 non-null    float64
 4   chol      303 non-null    int64  
 5   fbs       299 non-null    float64
 6   restecg   297 non-null    float64
 7   thalachh  303 non-null    int64  
 8   exng      303 non-null    int64  
 9   oldpeak   300 non-null    float64
 10  slp       302 non-null    float64
 11  caa       301 non-null    float64
 12  thall     301 non-null    float64
 13  output    302 non-null    float64
dtypes: float64(10), int64(4)
memory usage: 33.3 KB
In [6]:
df.columns
Out[6]:
Index(['age', 'sex', 'cp', 'trtbps', 'chol', 'fbs', 'restecg', 'thalachh',
       'exng', 'oldpeak', 'slp', 'caa', 'thall', 'output'],
      dtype='object')
In [7]:
df.isnull().sum()
Out[7]:
age         3
sex         1
cp          0
trtbps      8
chol        0
fbs         4
restecg     6
thalachh    0
exng        0
oldpeak     3
slp         1
caa         2
thall       2
output      1
dtype: int64
In [8]:
df1=df.copy()
In [9]:
df.fillna(method="ffill",inplace=True)
In [10]:
df.isnull().sum()
Out[10]:
age         0
sex         0
cp          0
trtbps      0
chol        0
fbs         0
restecg     0
thalachh    0
exng        0
oldpeak     0
slp         0
caa         0
thall       0
output      0
dtype: int64
In [11]:
df.duplicated().sum()
Out[11]:
1
In [12]:
df.drop_duplicates(inplace=True)
In [13]:
df.duplicated().sum()
Out[13]:
0
In [14]:
df.describe()
Out[14]:
age sex cp trtbps chol fbs restecg thalachh exng oldpeak slp caa thall output
count 302.000000 302.000000 302.000000 302.000000 302.000000 302.000000 302.000000 302.000000 302.000000 302.000000 302.000000 302.000000 302.000000 302.000000
mean 54.307947 0.685430 0.963576 131.847682 246.500000 0.152318 0.526490 149.569536 0.327815 1.040066 1.394040 0.728477 2.311258 0.543046
std 9.058753 0.465115 1.032044 17.458541 51.753489 0.359925 0.526027 22.903527 0.470196 1.163174 0.615711 1.007835 0.612011 0.498970
min 29.000000 0.000000 0.000000 94.000000 126.000000 0.000000 0.000000 71.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
25% 47.250000 0.000000 0.000000 120.000000 211.000000 0.000000 0.000000 133.250000 0.000000 0.000000 1.000000 0.000000 2.000000 0.000000
50% 55.000000 1.000000 1.000000 130.000000 240.500000 0.000000 1.000000 152.500000 0.000000 0.800000 1.000000 0.000000 2.000000 1.000000
75% 61.000000 1.000000 2.000000 140.000000 274.750000 0.000000 1.000000 166.000000 1.000000 1.600000 2.000000 1.000000 3.000000 1.000000
max 77.000000 1.000000 3.000000 200.000000 564.000000 1.000000 2.000000 202.000000 1.000000 6.200000 2.000000 4.000000 3.000000 1.000000
In [15]:
df["output"].value_counts()
Out[15]:
1.0    164
0.0    138
Name: output, dtype: int64
In [16]:
#converting numerical data into categorical data
def heart_disease(row):
    if row==0:
        return "Absence" # it indicates that the person has not have  heart disease
    elif row==1:
        return "Presence" # it indicates that the person has heart disease
In [17]:
#adding converted data into our dataset with new column-Heart_disease
df["Heart_Disease"]=df["output"].apply(heart_disease)
df.head()
Out[17]:
age sex cp trtbps chol fbs restecg thalachh exng oldpeak slp caa thall output Heart_Disease
0 63.0 1.0 3 145.0 233 1.0 0.0 150 0 2.3 0.0 0.0 1.0 1.0 Presence
1 37.0 1.0 2 130.0 250 0.0 1.0 187 0 3.5 0.0 0.0 2.0 1.0 Presence
2 41.0 0.0 1 130.0 204 0.0 0.0 172 0 1.4 2.0 0.0 2.0 1.0 Presence
3 41.0 1.0 1 120.0 236 0.0 1.0 178 0 0.8 2.0 0.0 2.0 1.0 Presence
4 57.0 0.0 0 120.0 354 0.0 1.0 163 1 0.6 2.0 0.0 2.0 1.0 Presence
In [18]:
df.groupby("Heart_Disease")['output'].count().plot(kind="pie",autopct='%1.1i%%',shadow=True)
font1={"family":"Algerian","color":"k","size":16}
plt.title("Heart Disease Population % ",fontdict=font1)
plt.legend(ncol=2,loc='upper right',bbox_to_anchor=(1.59,1.02))
plt.show()

The pie plot tells that presence has more percentage than absence of heart diseases.¶

In [29]:
sns.axes_style()
plt.figure(figsize=[18,5])
font1={"family":"Algerian","color":"brown","size":20}
font2={"family":"Arial Rounded MT Bold","color":"r","size":16}
sns.countplot(x='age',data=df)
custome={"axes.edgecolor":"yellow","grid.linestyle":"--",'grid.color':"cyan"}
sns.set_style("darkgrid",rc=custome)
plt.xlabel("AGE",fontdict=font1)
plt.ylabel("Count",fontdict=font2)
plt.show()

We Can Observe that the count of population according to their age,eg:Young age,Middle age,Elder people¶

In [20]:
#statistical analysis 
Min_age=df["age"].min()
Max_age=df["age"].max()
Mean_age=df["age"].mean()
print("minimum age =",Min_age)
print("maximum age =",Max_age)
print("Mean age =",Mean_age)
minimum age = 29.0
maximum age = 77.0
Mean age = 54.30794701986755
In [21]:
#categorical analysis
Young_age=df[(df["age"]>=29)&(df["age"]<40)]
Middle_age=df[(df["age"]>=40)&(df["age"]<55)]
Elder_age=df[(df["age"]>=55)]
print("Young Age =",len(Young_age))
print("Middle Age =",len(Middle_age))
print("Elder Age =",len(Elder_age))
Young Age = 15
Middle Age = 130
Elder Age = 157
In [30]:
font1={"family":"Algerian","color":"brown","size":16}
font2={"family":"Arial Rounded MT Bold","color":"r","size":16}
font3={"family":"Algerian","color":"k","size":16}
sns.barplot(x=["Young_age","Middle_age","Elder_age"],y=[len(Young_age),len(Middle_age),len(Elder_age)],palette='colorblind')
plt.xlabel("Age Range",fontdict=font1)
plt.ylabel("Count",fontdict=font2)
plt.title("Age Category",fontdict=font3)
plt.show()

From the above plot, I observed that elder age population is more than the middle age and young age population.And there is a least population of Young age.¶

In [23]:
#converting numerical data into categorical data
def gender(row):
    if row==1:
        return "Male"
    elif row==0:
        return "Female"
In [24]:
# adding converted data into our dataset with new column-Gender
df["Gender"]=df["sex"].apply(gender)
df.head()
Out[24]:
age sex cp trtbps chol fbs restecg thalachh exng oldpeak slp caa thall output Heart_Disease Gender
0 63.0 1.0 3 145.0 233 1.0 0.0 150 0 2.3 0.0 0.0 1.0 1.0 Presence Male
1 37.0 1.0 2 130.0 250 0.0 1.0 187 0 3.5 0.0 0.0 2.0 1.0 Presence Male
2 41.0 0.0 1 130.0 204 0.0 0.0 172 0 1.4 2.0 0.0 2.0 1.0 Presence Female
3 41.0 1.0 1 120.0 236 0.0 1.0 178 0 0.8 2.0 0.0 2.0 1.0 Presence Male
4 57.0 0.0 0 120.0 354 0.0 1.0 163 1 0.6 2.0 0.0 2.0 1.0 Presence Female
In [25]:
#converting numerical data into categorical data 
def age_range(row):
    if row>=29 and row<40:
        return "Young Age"
    elif row>=40 and row<55:
        return "Middle Age"
    elif row>=55:
        return "Elder Age"
In [26]:
#adding converting data into our dataset with new column-Age_range
df["Age_range"]=df["age"].apply(age_range)
df.head()
Out[26]:
age sex cp trtbps chol fbs restecg thalachh exng oldpeak slp caa thall output Heart_Disease Gender Age_range
0 63.0 1.0 3 145.0 233 1.0 0.0 150 0 2.3 0.0 0.0 1.0 1.0 Presence Male Elder Age
1 37.0 1.0 2 130.0 250 0.0 1.0 187 0 3.5 0.0 0.0 2.0 1.0 Presence Male Young Age
2 41.0 0.0 1 130.0 204 0.0 0.0 172 0 1.4 2.0 0.0 2.0 1.0 Presence Female Middle Age
3 41.0 1.0 1 120.0 236 0.0 1.0 178 0 0.8 2.0 0.0 2.0 1.0 Presence Male Middle Age
4 57.0 0.0 0 120.0 354 0.0 1.0 163 1 0.6 2.0 0.0 2.0 1.0 Presence Female Elder Age
In [31]:
plt.figure(figsize=[10,5])
font1={"family":"Algerian","color":"brown","size":16}
font2={"family":"Arial Rounded MT Bold","color":"r","size":16}
font3={"family":"Algerian","color":"k","size":16}
sns.stripplot(x="Age_range",y="age",data=df,hue="Gender",order=["Young Age","Middle Age","Elder Age"])
plt.xlabel("Age Category",fontdict=font1)
plt.ylabel("Age",fontdict=font2)
plt.title("Gender Based Age Category",fontdict=font3)
plt.legend(title="Gender",ncol=2,loc='upper right',bbox_to_anchor=(1.28,1))
plt.show()

In the given dataset the number of male Population is more than the female population in each group.¶

In [32]:
plt.figure(figsize=[10,5])
font1={"family":"Algerian","color":"brown","size":16}
font2={"family":"Arial Rounded MT Bold","color":"r","size":16}
font3={"family":"Algerian","color":"k","size":16}
hue_orders=["Young Age","Middle Age","Elder Age"]
sns.countplot(x="Heart_Disease",hue="Age_range",data=df,hue_order=hue_orders,order=["Absence","Presence"],palette="muted")
plt.xlabel("Heart Disease",fontdict=font1)
plt.ylabel("Count",fontdict=font2)
plt.title("Heart disease Based Age Category",fontdict=font3)
plt.legend(title="Age_range",ncol=2,loc='upper right',bbox_to_anchor=(1.28,1.20))
plt.show()

Middle Age people are more effected by heart disease and young age people are rarely effected¶

In [33]:
plt.figure(figsize=[5,5])
font1={"family":"Algerian","color":"brown","size":16}
font2={"family":"Arial Rounded MT Bold","color":"r","size":16}
font3={"family":"Algerian","color":"k","size":16}
sns.countplot(x="Heart_Disease",hue="Gender",data=df,palette="deep")
plt.xlabel("Heart Disease",fontdict=font1)
plt.ylabel("Count",fontdict=font2)
plt.title("Heart disease Based on gender",fontdict=font3)
plt.legend(title="Gender",ncol=2,loc='upper right',bbox_to_anchor=(1.52,1.02))
plt.show()

From the above Graph,It is observed that there are more number of males are effected by heart diseases compare to females¶

In [288]:
plt.figure(figsize=[10,5])
font1={"family":"Algerian","color":"brown","size":16}
font2={"family":"Arial Rounded MT Bold","color":"r","size":16}
font3={"family":"Algerian","color":"k","size":16}
sns.countplot(x="Heart_Disease",hue="cp",data=df,palette="deep")
plt.xlabel("Heart Disease",fontdict=font1)
plt.ylabel("Count",fontdict=font2)
plt.title("Chest Pain Experienced",fontdict=font3)
plt.legend(labels=["Typical Angina","Atypical Angina","Asymptomatic","Non-Anginal"],bbox_to_anchor=(1.20,1.02))
plt.show()

It is observed that people having asymptomatic chest pain have higher chance of heart diseases.¶

In [294]:
plt.figure(figsize=[10,5])
font1={"family":"Algerian","color":"brown","size":16}
font2={"family":"Arial Rounded MT Bold","color":"r","size":16}
font3={"family":"Algerian","color":"k","size":16}
sns.countplot(x="Gender",hue="cp",data=df,palette="colorblind")
plt.xlabel("Sex",fontdict=font1)
plt.ylabel("Count",fontdict=font2)
plt.title("Chest Pain Based On Gender",fontdict=font3)
plt.legend(labels=["Asymptomatic","Atypical Angina","Typical","Non-Anginal"],bbox_to_anchor=(1.20,1.02))
plt.show()

It is observed that higher number of males are suffering from asymptomatic chest pain.¶

In [291]:
plt.figure(figsize=[10,5])
font1={"family":"Algerian","color":"brown","size":16}
font2={"family":"Arial Rounded MT Bold","color":"r","size":16}
font3={"family":"Algerian","color":"k","size":16}
sns.countplot(x="Age_range",hue="cp",data=df,order=["Young Age","Middle Age","Elder Age"],palette="colorblind")
plt.xlabel("Age Category",fontdict=font1)
plt.ylabel("Count",fontdict=font2)
plt.title("Chest Pain Based On Age Category",fontdict=font3)
plt.legend(labels=["Asymptomatic","Typical Angina","Atypical Angina","Non-Anginal"],bbox_to_anchor=(1.20,1.02))
plt.show()

It seems that elder age group have very high asymptomatic chest pain.¶

In [262]:
plt.figure(figsize=[8,5])
font1={"family":"Algerian","color":"brown","size":16}
font2={"family":"Arial Rounded MT Bold","color":"r","size":16}
font3={"family":"Algerian","color":"k","size":16}
sns.barplot(x="Gender",y="trtbps",data=df,palette="plasma")
plt.xlabel("Sex",fontdict=font1)
plt.ylabel("Persons Resting Blood Pressure(mm Hg)",fontdict=font2)
plt.title("Blood Pressure",fontdict=font3)
plt.show()

It is observed that Person's Resting Blood Pressure is almost same for males and females.¶

In [263]:
plt.figure(figsize=[8,5])
font1={"family":"Algerian","color":"brown","size":16}
font2={"family":"Arial Rounded MT Bold","color":"r","size":16}
font3={"family":"Algerian","color":"k","size":16}
sns.barplot(x="Gender",y="chol",data=df,palette="turbo")
plt.xlabel("Sex",fontdict=font1)
plt.ylabel("Cholestrol",fontdict=font2)
plt.title("Cholestrol level Based On Gender",fontdict=font3)
plt.show()

It is observed that the cholestrol level is little bit more in females than males¶

In [295]:
plt.figure(figsize=[8,5])
font1={"family":"Algerian","color":"brown","size":16}
font2={"family":"Arial Rounded MT Bold","color":"r","size":16}
font3={"family":"Algerian","color":"k","size":16}
sns.barplot(x="Heart_Disease",y="chol",data=df,order=["Absence","Presence"])
plt.xlabel("Heart Disease",fontdict=font1)
plt.ylabel("Cholestrol",fontdict=font2)
plt.title("Cholestrol vs Heart Disease",fontdict=font3)
plt.show()

people who doesn't have cholestrol are also effected by heart disease.¶

In [265]:
plt.figure(figsize=[8,5])
font1={"family":"Algerian","color":"brown","size":16}
font2={"family":"Arial Rounded MT Bold","color":"r","size":16}
font3={"family":"Algerian","color":"k","size":16}
sns.barplot(x="Heart_Disease",y="trtbps",data=df,palette="muted")
plt.xlabel("Heart Disease",fontdict=font1)
plt.ylabel("Blood Pressure",fontdict=font2)
plt.title("Blood Pressure vs Heart Disease",fontdict=font3)
plt.show()

people who doesn't have any Heart disease have more Blood Pressure compare to the people having heart disease.¶

In [266]:
plt.figure(figsize=[15,5])
font1={"family":"Algerian","color":"brown","size":16}
font2={"family":"Arial Rounded MT Bold","color":"r","size":16}
font3={"family":"Algerian","color":"k","size":16}
sns.lineplot(x="age",y="trtbps",data=df,color="r",marker="o",ms=5,mec="k",mfc="orange",ls="-")
plt.xlabel("AGE",fontdict=font1)
plt.ylabel("Blood Pressure",fontdict=font2)
plt.title("Age vs Blood Pressure",fontdict=font3)
plt.show()

Here I observed that the blood pressure is normal from age 30 to 50 and after 50 it increases gradually to age of 60.And after age of 60 it is fluctuating drastically.¶

In [267]:
plt.figure(figsize=[15,5])
font1={"family":"Algerian","color":"brown","size":16}
font2={"family":"Arial Rounded MT Bold","color":"r","size":16}
font3={"family":"Algerian","color":"k","size":16}
sns.lineplot(x="age",y="chol",data=df,color="b",marker="o",ms=5,mec="k",mfc="orange",ls="-")
plt.xlabel("AGE",fontdict=font1)
plt.ylabel("Cholestrol",fontdict=font2)
plt.title("Age vs cholestrol",fontdict=font3)
plt.show()

cholestrol level is start increasing at the age of 50.¶

In [268]:
plt.figure(figsize=[15,5])
font1={"family":"Algerian","color":"brown","size":16}
font2={"family":"Arial Rounded MT Bold","color":"r","size":16}
font3={"family":"Algerian","color":"k","size":16}
sns.lineplot(x="age",y="oldpeak",data=df,color="g",marker="o",ms=5,mec="k",mfc="orange",ls="-")
plt.xlabel("AGE",fontdict=font1)
plt.ylabel("ST Deprsession",fontdict=font2)
plt.title("ST Depression vs Age",fontdict=font3)
plt.show()

Depression level is quite high in the age group of 30 to 40 and 55 to 70.And in the age group of 40 to 55,it remains stable.¶

In [300]:
plt.figure(figsize=[8,5])
font1={"family":"Algerian","color":"brown","size":16}
font2={"family":"Arial Rounded MT Bold","color":"r","size":16}
font3={"family":"Algerian","color":"k","size":16}
sns.barplot(x="Gender",y="oldpeak",data=df,palette="viridis")
plt.xlabel("Sex",fontdict=font1)
plt.ylabel("ST Depression",fontdict=font2)
plt.title("ST Depression vs Gender",fontdict=font3)
plt.show()

It is observed that the Males are getting more depressed than females.¶

In [270]:
plt.figure(figsize=[8,5])
font1={"family":"Algerian","color":"brown","size":16}
font2={"family":"Arial Rounded MT Bold","color":"r","size":16}
font3={"family":"Algerian","color":"k","size":16}
sns.barplot(x="Heart_Disease",y="exng",data=df,palette="tab20")
plt.xlabel("Heart Disease",fontdict=font1)
plt.ylabel("Exercise With Angina",fontdict=font2)
plt.title("Exercise With Angina vs Heart Disease",fontdict=font3)
plt.show()

It is observed that if the people who suffered with angina,whether he/her do exercise or not,can also have heart diseases.¶

In [271]:
plt.figure(figsize=[8,5])
font1={"family":"Algerian","color":"brown","size":16}
font2={"family":"Arial Rounded MT Bold","color":"r","size":16}
font3={"family":"Algerian","color":"k","size":16}
sns.barplot(x="Gender",y="exng",data=df,palette="binary_r")
plt.xlabel("Sex",fontdict=font1)
plt.ylabel("Exercise With Angina",fontdict=font2)
plt.title("Exercise With Angina vs Gender",fontdict=font3)
plt.show()

Male category having high exercise induced Angina.¶

In [272]:
plt.figure(figsize=[8,5])
font1={"family":"Algerian","color":"brown","size":16}
font2={"family":"Arial Rounded MT Bold","color":"r","size":16}
font3={"family":"Algerian","color":"k","size":16}
sns.barplot(x="Gender",y="fbs",data=df,palette="turbo")
plt.xlabel("Sex",fontdict=font1)
plt.ylabel("Fasting Blood Sugar",fontdict=font2)
plt.title("Fasting Blood Sugar vs Gender",fontdict=font3)
plt.show()

It is Observed that males having high fasting blood pressure > 120mg/dl¶

In [284]:
plt.figure(figsize=[10,5])
sns.heatmap(df.corr(),annot=True,cbar=True,linewidth=1,linecolor="White",cmap="tab20")
Out[284]:
<Axes: >
In [ ]:
Performed EDA by using Pandas Profiling:
In [277]:
profile=df.profile_report()
profile
Summarize dataset:   0%|          | 0/5 [00:00<?, ?it/s]
Generate report structure:   0%|          | 0/1 [00:00<?, ?it/s]
Render HTML:   0%|          | 0/1 [00:00<?, ?it/s]
Out[277]:

In [278]:
profile.to_file("Heart Disease Diagnostic Analysis profile report.html")
Export report to file:   0%|          | 0/1 [00:00<?, ?it/s]
In [ ]:
#exporting final dataset to as csv file for dashboarding in power BI
df.to_csv("Cheart.csv",index=False)
In [ ]: